#pragma warning(disable:4996)
#include<iostream>
#include<string>
using namespace std;

int n=0;//字符数
int word=0;//单词数
int sentence=0;//句子数
int main(int argc, char* argv[])
{
	FILE* fp = fopen(argv[2], "r");
	if (fp == NULL)//判断是否打开文件
	{
		printf("打开失败\n");
		return 0;
	}
	else if (strcmp(argv[1], "-c") == 0)//统计字符数
	{
		char i;
		while (!feof(fp))//文件读取到结尾时停止
		{
			i = fgetc(fp);//读取一个字符
			if (i != ' ' && i != '\n' && i != '\t')//非空格，换行符时字符数+1
			{
				n++;
			}
		}
		cout << "字符数：" << n << endl;
	}
	else if (strcmp(argv[1], "-w") == 0)//统计单词数
	{
		char m;
		while (!feof(fp))
		{
			m = fgetc(fp);
			if (m == ' ' || m == ',' || m == '.' || m == '!' || m == '?'|| m == '\n')//读取到空格，逗号等单词分隔字符时单词数+1
			{
				word++;
			}
		}
		cout << "单词数为：" << word << endl;
	}
	else if (strcmp(argv[1], "-s") == 0)//统计句子数
	{
		char s;
		while (!feof(fp))
		{
			s = fgetc(fp);
			if (s == '.' || s == '?' || s == '!')//读取到句号、问号、感叹号等句子结尾标识符时句子数+1
			{
				sentence++;
			}
		}
		cout << "句子数：" << sentence << endl;
	}
	fclose(fp);
}